package com.ambulance.framework.task;

import com.ambulance.project.biz.entity.Class;
import com.ambulance.project.biz.entity.Doctor;
import com.ambulance.project.biz.entity.Nurse;
import com.ambulance.project.biz.service.ClassService;
import com.ambulance.project.biz.service.DoctorService;
import com.ambulance.project.biz.service.NurseService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 定时任务调度测试
 *
 * @author zhao
 */
@Component("onDutyTask")
public class OnDutyTask {


    private ClassService classService;
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private NurseService nurseService;

    public void ryNoParams() {
        System.out.println("执行无参方法");
        LocalDateTime now = LocalDateTime.now();
        String currentDay = now.getDayOfWeek().getValue() + "";
        // 获取当前排班信息，并修改排班内人员的状态
        QueryWrapper<Class> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", "0");
        List<Class> list = classService.list(queryWrapper);

        for (Class item : list) {
            String weekID = item.getWeekID();
            if (weekID.contains(currentDay)) {
                // 在值班日期
                // 更新班组内人员值班状态
                Doctor doctor = new Doctor();
                doctor.setDoctorID(item.getDoctorID());
                doctor.setOnDutyStatus(1);
                doctorService.updateById(doctor);

                Nurse nurse = new Nurse();
                nurse.setNurseID(item.getNurseID());
                nurse.setOnDutyStatus(1);
                nurseService.updateById(nurse);

            } else {
                // 当前不再排班中
                Doctor doctor = new Doctor();
                doctor.setDoctorID(item.getDoctorID());
                doctor.setOnDutyStatus(0);
                doctorService.updateById(doctor);

                Nurse nurse = new Nurse();
                nurse.setNurseID(item.getNurseID());
                nurse.setOnDutyStatus(0);
                nurseService.updateById(nurse);
            }

        }
        // 更新 如上的医生和护士未值班状态


    }
}
